﻿using System;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using KKCai.SC.App.Model;
using KKCai.SC.App;

namespace KKCai.SC.Job
{
    internal class MyJob : Quartz.IJob
    {
        #region IJob 成员
        private const string url = "http://trade.aicairen.com/ajax/openterm.aspx?lotType=xysc";
        public void Execute(Quartz.JobExecutionContext context)
        {
            string resp = new WebUtils().DoGet(url);

            if (String.IsNullOrEmpty(resp))
                return;

            JObject o = JObject.Parse(resp);

            string msg = (string)o.SelectToken("Msg");

            if (msg == "success")
            {
                object obj = (object)o.SelectToken("OpenList[0]");

                RecordInfo r = JsonConvert.DeserializeObject<RecordInfo>(obj.ToString());

                new Manager().Save(r);
            }
        }

        #endregion
    }
}
